home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 386 / utility / speedtst.s < prev    next >
Text File  |  1985-11-19  |  10KB  |  231 lines

  1.  ; Program Name: SPEEDTST.S
  2.  ; Version: 1.006
  3.  
  4.  ; Assembly Instructions:
  5.  
  6.  ;     Assemble in "PC-relative" mode and save with a TTP extension. 
  7.  
  8.  ; Function:
  9.  
  10.  ;     Spawn the TOS or PRG process typed on the command line.  Create a disk
  11.  ; file which is to be identified by the name of the spawned program with a
  12.  ; DAT suffix.  The disk file is to reside in the same directory as does the
  13.  ; spawned process.
  14.  
  15.  ;     Calculate the spawned program's load and execution times and store them
  16.  ; in the file.  If the spawned process directs output to the video screen via
  17.  ; GEMDOS function $9, redirect that output to the file.
  18.  
  19.  ; Execution Instructions:
  20.  
  21.  ;     SPEEDTST.TTP will not execute unless the custom traps in program
  22.  ; TRAPS.PRG have previously been installed.
  23.  
  24.  ;     Execute from the desktop.  Type the name of an executable file which
  25.  ; has a TOS or PRG extension on SPEEDTST.TTP's input parameter line.  The
  26.  ; name of the program you type on the parameter line must be in the same
  27.  ; directory as is SPEEDTST.TTP.  The program must terminate with GEMDOS
  28.  ; function $4C, and, via that function, it must pass to SPEEDTST.TTP the
  29.  ; word length portion of the value that was in memory location $4BA
  30.  ; immediately after it was loaded.
  31.  
  32.  ;     The longword value in $4BA can be obtained by invoking custom trap #3
  33.  ; (get_time).  SPEEDTST.TTP uses the word length portion of that value,
  34.  ; which is returned in D0 by GEMDOS $4C, to calculate the spawned program's
  35.  ; load and execution times.
  36.  
  37.  ;     If the spawned program contains any instructions that cause it to pause,
  38.  ; such as those that wait for a keypress or some other event, those should be
  39.  ; commented out, and the program should be assembled especially for the speed
  40.  ; test.  Otherwise the execution time computed by SPEEDTEST.TTP will include
  41.  ; the time that the spawned program was waiting for the event to occur.  
  42.  
  43.  ;     If custom trap #8 is used to terminate the spawned program, the trap
  44.  ; will execute a wait_for_keypress algorithm when the program is executed from
  45.  ; the desktop, but it will omit the wait algorithm when the program is spawned
  46.  ; by SPEEDTST.TTP.  In addition, trap #8 will return the after-load value to
  47.  ; SPEEDTST.TTP and terminate the spawned program with GEMDOS function $4C.
  48.  
  49.  ;     Both trap #8 and SPEEDTST.TTP require that the spawned program be
  50.  ; initialized with custom trap #6 or a similar algorithm.  See TRAPS.S for
  51.  ; details about custom traps #6 and #8.
  52.  
  53. release_excess_memory:
  54.  lea        -$82(pc), a3        ; Put "command line" address in A3.
  55.  lea        -$80(a3), a1        ; Put "basepage" address in A1.
  56.  lea        program_end, a0     ; Put "end of program" address in A0.
  57.  trap       #6                  ; Calculate program size and release memory.
  58.  
  59.  ; NOTE: A local stack is not declared in PRG_5AP.TOS.  Because of the long
  60.  ;       string that is printed by that program, this program will bomb when
  61.  ;       it spawns PRG_5AP.TOS, if a local stack is not declared here.
  62.  
  63.  lea        stack, a7           ; Point A7 to this program's stack.
  64.  
  65. process_command_line:
  66.  lea        command_line, a4    ; Fetch location to contain command line.
  67.  movem.l    (a3), d0-d3         ; Move 16 bytes of command line to 4 registers.
  68.  movem.l    d0-d3, (a4)         ; Move them to address "command_line".
  69.  move.b     (a3)+, d0           ; Fetch command line ASCII character count.
  70.  ext.w      d0                  ; Extend to word for next instruction.
  71.  move.b     #0, 1(a4,d0.w)      ; Store a null at end of string.
  72.  
  73.  lea        program_name, a0    ; Fetch address of pointer to command line.
  74.  move.l     a3, (a0)            ; Store address of command line string at
  75.                                 ; pointer.
  76.  move.b     #0, 0(a3,d0.w)      ; Replace $0D at end of command line input
  77.                                 ; in basepage with a NULL.
  78.  
  79. insert_filename_suffix:
  80.  move.b     #$44, -2(a4,d0.w)   ; Insert letter 'D'.
  81.  move.b     #$41, -1(a4,d0.w)   ; Insert letter 'A'.
  82.  move.b     #$54,  0(a4,d0.w)   ; Insert letter 'T'.
  83.  
  84. create_file:
  85.  move.w     #0, -(sp)           ; File attribute = read/write.
  86.  pea        filename            ; Will be name of spawned process + .DAT.
  87.  move.w     #$3C, -(sp)         ; Function = f_create = GEMDOS $3C.
  88.  trap       #1                  ; File handle is returned in D0.
  89.  addq.l     #8, sp
  90.  lea        file_handle, a0     ; Store returned file handle.
  91.  move.w     d0, (a0)
  92.  
  93. redirect_output:                ; Exchange file handle with screen's handle.
  94.  move.w     file_handle, -(sp)  ; This is the disk file's handle.
  95.  move.w     #1, -(sp)           ; This is the video screen's handle.
  96.  move.w     #$46, -(sp)         ; Function = f_force = GEMDOS $46.
  97.  trap       #1
  98.  addq.l     #6, sp
  99.  
  100. prepare_stack_for_load_and_execute_program:      
  101.  pea        environ_string
  102.  pea        command_string
  103.  pea        (a3)                ; Push address of program name string.
  104.  move.w     #0, -(sp)
  105.  move.w     #$4B, -(sp)         ; Function = GEMDOS $4B = p_exec.
  106. get_start_time:
  107.  lea        start_time, a3      ; Fetch address of variable "start_time".
  108.  trap       #3                  ; Returns value of system clock in D0.
  109.  move.w     d0, (a3)            ; Save start time.
  110. load_and_execute_program:
  111.  trap       #1                 
  112.  move.w     d0, d3              ; Copy after-load value to D3 for calculation.
  113.  
  114. get_end_time:
  115.  trap       #3                  ; Returns value of system clock in D0.
  116.  move.w     d0, d5              ; Copy to D5 for calculation.
  117.  sub.w      d3, d5              ; Subtract after-load time from end time.
  118.  ext.l      d5                  ; Extend to 32 bits.
  119.  
  120. reposition_stack_pointer:
  121.  lea        $10(sp), sp        
  122.  
  123. get_drive:
  124.  move.w     #$19, -(sp)         ; Function = dgetdrv = GEMDOS $19.
  125.  trap       #1                  ; Returns 0 for drive A, 1 for B, etc.
  126.  addq.l     #2, sp              
  127.  add.b      #$41, d0            ; Add ASCII value for A to compute ASCII
  128.  lea        drive, a0           ; letter code for the drive value returned.
  129.  move.b     d0, (a0)            ; Save drives ASCII leter code.
  130.  
  131. print_heading:
  132.  lea        heading, a0
  133.  bsr        print_string
  134.  lea        program_name, a0     ; Fetch address of program name string.
  135.  movea.l    (a0), a0
  136.  bsr        print_string
  137. print_drive_for_spawned_program:
  138.  lea        drive_msg, a0
  139.  bsr        print_string
  140.  
  141. compute_load_time:
  142.  lea        load_time_msg, a0
  143.  bsr        print_string
  144.  lea        start_time, a3
  145.  sub.w      (a3), d3            ; Subtract start time from after-load time.
  146.  ext.l      d3                  ; Extent to 32 bits.
  147.  
  148. multiply_by_five:               ; Convert to milliseconds.
  149.  move.l     d3, d0              ; Save a copy to add.
  150.  asl.l      #2, d3              ; Shift to multiply by 4.
  151.  add.l      d0, d3              ; To complete multiplication by 5.
  152.  
  153. print_load_time:
  154.  cmpi.l     #999, d3            ; If load time is less than 1000, then
  155.  bgt        no_space            ; print a leading blank space for output
  156.  lea        space, a0           ; alignment.
  157.  bsr        print_string
  158.  cmpi.l     #99, d3             ; If load time is less than 100, then
  159.  bgt        no_space            ; print another leading blank space.
  160.  lea        space, a0
  161.  bsr        print_string
  162. no_space:
  163.  move.l     d3, d1              ; Copy load time to D1 for decimal conversion.       
  164.  trap       #4                  ; Returns address of decimal string in A0.
  165.  bsr.s      print_string
  166.  lea        units_label, a0
  167.  bsr.s      print_string
  168.  
  169. compute_execution_time:         ; D5 already contains the execution time.
  170.  lea        execute_time_msg, a0; Here, it must only be multiplied by 5 to
  171.  bsr.s      print_string        ; be converted to milliseconds.
  172.  move.l     d5, d0              ; Save a copy to add.
  173.  asl.l      #2, d5              ; Shift to multiply by 4.
  174.  add.l      d0, d5              ; To complete multiplication by 5.
  175.  
  176. print_execution_time:
  177.  cmpi.l     #999, d5            ; If execute time is less than 1000, then
  178.  bgt        _no_space           ; print a leading blank space for output
  179.  lea        space, a0           ; alignment.
  180.  bsr        print_string
  181.  cmpi.l     #99, d5             ; If execute time is less than 100, then
  182.  bgt        _no_space           ; print another leading blank space.
  183.  lea        space, a0
  184.  bsr        print_string
  185. _no_space:
  186.  move.l     d5, d1              ; Copy execute time for decimal conversion.
  187.  trap       #4                  ; Returns address of decimal string in A0.
  188.  bsr.s      print_string
  189.  lea        units_label, a0
  190.  bsr.s      print_string
  191.  
  192. close_file:
  193.  move.w     file_handle, -(sp)
  194.  move.w     #$3E, -(sp)         ; Function = fclose = GEMDOS $3E.
  195.  trap       #1
  196.  addq.l     #4, sp
  197.  
  198. terminate:
  199.  move.w     #0, -(sp)
  200.  trap       #1
  201.  
  202. print_string:                   ; Expects address of string to be in A0.
  203.  pea        (a0)                ; Push address of string onto stack.
  204.  move.w     #9, -(sp)           ; Function = c_conws = GEMDOS $9.
  205.  trap       #1                  ; GEMDOS call
  206.  addq.l     #6, sp              ; Reset stack pointer to top of stack.
  207.  rts
  208.  
  209.  data
  210. space:            dc.b " ",0
  211. heading:          dc.b $D,$A,"SPEEDTST.TTP Execution Results",$D,$A
  212.                   dc.b       "for ",0
  213. drive_msg:        dc.b ", loaded from drive: "
  214. drive:            dc.b "A",$D,$A,0
  215. load_time_msg:    dc.b $D,$A,"  Load time:      ",0
  216. execute_time_msg: dc.b       "  Execution time: ",0
  217. units_label:      dc.b " milliseconds",$D,$A,0
  218. environ_string:   dc.b "TERM",0
  219. command_string:   dc.b 0
  220.  align
  221.  bss
  222. start_time:       ds.w    1     ; Value in $4BA just before spawning.
  223. program_name:     ds.l    1     ; Pointer to name in basepage command line.
  224. file_handle:      ds.w    1     ; Handle for the filename below.
  225. command_line:     ds.b    1     ; Unused character count will go here.
  226. filename:         ds.b   15     ; File name for redirected output.
  227.                   ds.l   96     ; Program stack.
  228. stack:            ds.l    0     ; Address of program stack.
  229. program_end:      ds.l    0
  230.  end
  231.